<?php
include "../model/model.php";

require "facebook_sdk/facebook.php";

$product_data[10];

$interest = $_GET['interest_product'];
$product_image = 'http://117.17.102.203/images/'.$_GET['product_image'];
$message = '사용자가 '.$interest.' 제품에 관심이 있습니다.';
if($interest == null){}
else {
$config = array(
    'appId' => '314860265232330',
    'secret' => 'de61791ac4eec6920ab83856c90b7861',
  );

  try{
		$facebook = new Facebook($config);
		$user_id = $facebook->getUser();		
		$user = $facebook->getUser();
		$user_profile = $facebook->api('/me');
		
	try {
        $ret_obj = $facebook->api('/me/feed', 'POST',
                                    array(
									  'name' => 'gnet',
									  'source' => $product_image,
                                      'link' => '117.17.102.203',
                                      'message' => $message,
									  'description' => '카메라 정보 공유 사이트 G-net 입니다.',
                                 ));
		echo("<script> alert('관심제품에 추가하였습니다..');</script>");
    } catch(FacebookApiException $e) {
        error_log($e->getType());
        error_log($e->getMessage());
    }   
 
		
		
		
		
		}catch (FacebookApiException $e){
		echo("<script> alert('Facebook 로그인이 되어있지않습니다.');</script>");
		echo("<script>location.replace('../view/product.html?product_name=$interest');</script>");
		}
	add_interest_product($interest, $user);
}

function get_product_data($product_name) {

	$product_data_array = get_product($product_name);
	
	
	$product_data = $product_data_array;
	return $product_data;
}

function add_interest_product($interest, $user) {
	interest_product($interest, $user);
	echo("<script>location.replace('../view/product.html?product_name=$interest');</script>");

}

?>